package com.YCH.article.controller.v1;

import com.YCH.apis.article.apis.ArticleInfoControllerApi;
import com.YCH.article.service.AppArticleInfoService;
import com.YCH.model.address.pojos.TbAreas;
import com.YCH.model.annotation.IdEncrypt;
import com.YCH.model.article.dtos.*;
import com.YCH.model.article.pojos.TbArticleCategory;
import com.YCH.model.behavior.dtos.userCommentReplayDto;
import com.YCH.model.common.dtos.ResponseResult;
import com.YCH.utils.common.IdsUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/article")
public class ArticleInfoController implements ArticleInfoControllerApi {

    @Autowired
    private AppArticleInfoService appArticleInfoService;

    /**
     * 获取文章配置
     * @param dto 封装参数对象
     * @return
     */
    @Override
    @PostMapping("/load_article_Info")
    public ResponseResult loadArticleInfo(@RequestBody ArticleInfoDto dto) {
        return appArticleInfoService.getArticleInfo(dto.getArticleId());
    }

    /**
     * 用户是否点赞，收藏，关注
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/load_article_behavior")
    public ResponseResult loadArticleBehavior(@RequestBody ArticleInfoDto dto) {
        return appArticleInfoService.loadArticleBehavior(dto);
    }

    /**
     * 点赞，查看，收藏，评论数量
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/load_article_action")
    public ResponseResult loadArticleAction(@RequestBody ArticleActionDto dto) {
        return appArticleInfoService.loadArticleAction(dto);
    }

    /**
     * 点赞，查看，收藏，评论数量，及其配置的合体接口
     * @param dto
     * @return
     */
    @Override
    @PostMapping("/load_article_action_and_config")
    public ResponseResult loadArticleActionAndConfig(@RequestBody  ArticleActionAndConfigDto dto) {
        return appArticleInfoService.loadArticleActionAndConfig(dto);
    }

    @Override
    @GetMapping("/load_article_comment")
    public ResponseResult loadArticleComments(@RequestParam(value = "articleId") String articleId,@RequestParam(value = "userId",required = false) String userId) {
        ArticleInfoDto articleInfoDto = new ArticleInfoDto();
        try {
            articleInfoDto.setArticleId(IdsUtils.decryptLong(articleId));
            if(userId!=null){
                articleInfoDto.setUserId(IdsUtils.decryptLong(userId));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return appArticleInfoService.loadArticleCommenty(articleInfoDto);
    }

    /**
     * 加载当前登录用户的云记
     * @param
     * @return
     */
    @Override
    @PostMapping("/load_local_user_cloudNoteN_list")
    public ResponseResult UserCloudNoteNList() {
        return appArticleInfoService.ObtainUserPrivateCloudNoteN();
    }

    /**
     * 获取用户地址
     * @param tbAreas
     * @return
     */
    @Override
    @PostMapping("/load_location")
    public ResponseResult UserLoacation(@RequestBody TbAreas tbAreas) {
        return appArticleInfoService.loadLocation(tbAreas);
    }
    @GetMapping("/load_comment_replay")
    @Override
    public ResponseResult loadUserCommentReplay(@RequestParam(value = "articleId")String articleId,
                                                @RequestParam(value = "commentId") String commentId,
                                                @RequestParam(value = "commentReplayId") String commentReplayId,
                                                @RequestParam(value = "pageSize",required = false) Integer pageSize,
                                                @RequestParam(value = "pageNum",required = false) Integer pageNum) {
        userCommentReplayDto dto = new userCommentReplayDto();
        try {
            dto.setArticleId(IdsUtils.decryptLong(articleId));
            dto.setCommentId(IdsUtils.decryptLong(commentId));
            dto.setCommentReplayId(IdsUtils.decryptLong(commentReplayId));
        } catch (Exception e) {
            e.printStackTrace();
        }
        dto.setPageSize(pageSize);
        dto.setPageNum(pageNum);
        return appArticleInfoService.loadCommentReplay(dto);
    }

}